//
//  XXCompoundInterestCalculationViewController.m
//  XingXue
//
//  Created by XingXue on 2024/1/30.
//  Copyright © 2024 XingXue. All rights reserved.
//

#import "XXCompoundInterestCalculationViewController.h"

#import "XXIncomeTaxCalculationTextCell.h"
#import "XXIncomeTaxCalculationTimeSelectCell.h"
#import "XXIncomeTaxCalculationButtonCell.h"

@interface XXCompoundInterestCalculationViewController ()

@property (nonatomic,copy) NSString *calculationItems;//计算项目
@property (nonatomic,copy) NSString *type;//复利方式
@property (nonatomic,copy) NSString *money;//存入本金（元）
@property (nonatomic,copy) NSString *rate;//利率（%）
@property (nonatomic,copy) NSString *term;//存入期限

@end

@implementation XXCompoundInterestCalculationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _calculationItems = @"本息合计(算终值)";
    _type = @"按年复利";
    
    [self setNavigationItemTitleViewWithTitle:@"复利计算"];

    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationTextCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationTextCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationTimeSelectCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationTimeSelectCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"XXIncomeTaxCalculationButtonCell" bundle:nil] forCellReuseIdentifier:@"XXIncomeTaxCalculationButtonCell"];
    
    self.tableView.frame = CGRectMake(0,self.navigationBarHeight, kScreenWidth, kScreenHeight - self.navigationBarHeight);
    [self.view bringSubviewToFront:self.navigationBar];
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;
        
        subarr = [NSMutableArray arrayWithCapacity:1];

        //计算项目
        dict =  @{@"class":XXIncomeTaxCalculationTimeSelectCell.class,
                  @"height":@([XXIncomeTaxCalculationTimeSelectCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTimeSelectCellModel ittemModelWithTitle:@"计算项目" content:_calculationItems position:0],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        
        //复利方式
        dict =  @{@"class":XXIncomeTaxCalculationTimeSelectCell.class,
                  @"height":@([XXIncomeTaxCalculationTimeSelectCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTimeSelectCellModel ittemModelWithTitle:@"复利方式" content:_type position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //存入本金（元）
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"存入本金（元）" content:_money tip:@"请输入本金金额" position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //利率（%）
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"利率（%）" content:_rate tip:@"请输入利率" position:1],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        //存入期限
        dict =  @{@"class":XXIncomeTaxCalculationTextCell.class,
                  @"height":@([XXIncomeTaxCalculationTextCell getCellFrame:[NSNumber numberWithFloat:64]]),
                  @"data":[XXIncomeTaxCalculationTextCellModel ittemModelWithTitle:@"存入期限" content:_term tip:@"输入存入期数" position:2],
                  @"delegate":@YES};
        [subarr addObject:dict];
        
        dict =  @{@"class":XXIncomeTaxCalculationButtonCell.class,
                  @"height":@([XXIncomeTaxCalculationButtonCell getCellFrame:[NSNumber numberWithFloat:110]]),
                  @"data":[XXIncomeTaxCalculationButtonCellModel ittemModelWithTitle:@"计算"],
                  @"delegate":@YES};
        [subarr addObject:dict];
                
        [arr addObject:subarr];

        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark XXIncomeTaxCalculationTextCellDelegate 存入本金（元）利率（%）存入期限
 
- (void)incomeTaxCalculationTextCell:(XXIncomeTaxCalculationTextCell *)cell textField:(UITextField *)textField {
    if ([cell.model.title isEqualToString:@"存入本金（元）"]) {
        _money = textField.text;
    } else if ([cell.model.title isEqualToString:@"利率（%）"]) {
        _rate = textField.text;
    } else if ([cell.model.title isEqualToString:@"存入期限"]) {
        _term = textField.text;
    }
}

#pragma mark - XXIncomeTaxCalculationTimeSelectCellDelegate 计算项目 复利方式

- (void)incomeTaxCalculationTimeSelectCell:(XXIncomeTaxCalculationTimeSelectCell *)cell buttonAction:(UIButton *)sender {
    if ([cell.model.title isEqualToString:@"计算项目"]) {
        
    } else if ([cell.model.title isEqualToString:@"复利方式"]) {
        
    }
}

#pragma mark - QBincomeTaxCalculationButtonCellDelegate 计算

- (void)incomeTaxCalculationButtonCell:(XXIncomeTaxCalculationButtonCell *)cell button:(UIButton *)sender {
    [self countButtonAction:sender];
}

#pragma mark - Action

//计算
- (void)countButtonAction:(UIButton *)sender {
    __block NSString *erro = @"";

    if (_term.length == 0) {
        erro = @"输入存入期数";
    }

    if (_rate.length == 0) {
        erro = @"请输入利率";
    }

    if (_money.length == 0) {
        erro = @"请输入本金金额";
    }

    if (erro.length > 0) {
        [self showProgressHUD:erro];
    } else {
        [self gotoGroupingResultsViewController];
    }
}

#pragma mark - goto

//添加内容
- (void)gotoGroupingResultsViewController {
//    DYGroupingResultsViewController *vc = [DYGroupingResultsViewController new];
//    vc.name = _name;
//    vc.count = _count;
//    vc.groupList = _groupList;
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
}

@end
